__author__ = 'Administrator'
from selenium import webdriver
import pytest
from pages.EnterPage import EnterPage
from pages.MainPage import MainPage
from pages.NewMessage import NewMessage
from pages.MovePopUpPage import MovePopUpPage
from pages.DeletePopUpPage import DeletePopUpPage


@pytest.fixture(scope='module')
def driver(request):
    firefox_driver = webdriver.Firefox()

    def quit_driver():
        #firefox_driver.quit()
        pass

    request.addfinalizer(quit_driver)

    return firefox_driver


RECIPIENT = "Administrator"
SUBJECT = "Subject of selenium auto test"
BODY = "Hello world!! This message body is transferred by selenium"

def test_send_message(driver):
    enter_page = EnterPage(driver)
    enter_page.open()
    enter_page.type_user_name()
    enter_page.type_password()
    enter_page.click_enter_button()

    main_page = MainPage(driver)
    main_page.click_new_message_button()

    new_message_page = NewMessage(driver)
    new_message_page.type_message_recepient(RECIPIENT)
    new_message_page.type_message_subject(SUBJECT)
    new_message_page.type_message_body(BODY)
    new_message_page.click_send_message()

    main_page.click_unread_mail_menu()
    main_page.go_to_last_unread_mail()
    main_page.click_delete_menu_button()

    delete_pop_up = DeletePopUpPage(driver)
    delete_pop_up.click_delete_button()

    main_page.click_deleted_mail_menu()
    main_page.click_move_menu_button()

    moving_page = MovePopUpPage(driver)
    moving_page.click_move_to_folder_menu()
    moving_page.click_move_to_inbox()
    moving_page.click_move_button()

    main_page.click_inbox_mail_menu()
    main_page.go_to_last_inbox_mail()

    restored_body, restored_recipient, restored_subject = main_page.get_email_info()

    assert restored_body == BODY, "Wrong mail body has been restored"
    assert restored_recipient == RECIPIENT, "Wrong mail recipient  has been restored"
    assert restored_subject == SUBJECT, "Wrong mail subject has been restored"
